package com.erp.common.web;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.erp.app.common.ProjectConstants;
import com.erp.framework.controller.action.SimpleMaintStyleAction;
import com.erp.framework.model.pk.SimpleBasePk;

public class PopUpAction extends SimpleMaintStyleAction{
	
	private Class masterFormClass;
    private Class masterVoClass;
    
    public static final String ACTION_ADD = "Add";
    
	protected void initForm(ActionMapping mapping, ActionForm formIn, HttpServletRequest request, 
            HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		PopUpForm form = (PopUpForm)formIn;
		
		this.masterFormClass = (Class)session.getAttribute(ProjectConstants.SESSION_POP_UP_MASTER_FORM_CLASS);
		session.removeAttribute(ProjectConstants.SESSION_POP_UP_MASTER_FORM_CLASS);
		
		this.masterVoClass = (Class)session.getAttribute(ProjectConstants.SESSION_POP_UP_MASTER_VO_CLASS);
		session.removeAttribute(ProjectConstants.SESSION_POP_UP_MASTER_VO_CLASS);
		
		HashMap params = (HashMap)session.getAttribute(ProjectConstants.SESSION_POP_UP_PARAMS);
		session.removeAttribute(ProjectConstants.SESSION_POP_UP_PARAMS);

		form.setParams(params);
		session.setAttribute(getMasterFormSessionName(), form);
	}
	
	protected String getModuleName(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response){
		return ProjectConstants.MOD_POP_UP;
	}

    protected String getFunctionId(){
    	return "popUp.do";
    }
       
    protected String getMasterFormSessionName(){
    	return "popUpForm";
    }
    
    protected Class getMasterFormClass(){
//    	System.out.print("******************** PopUpAction, class of form is: " + this.masterFormClass.getName());
//    	return this.masterFormClass;
    	return PopUpForm.class;
    }
    
    protected Class getMasterVOClass(){
    	System.out.print("******************** PopUpAction, class of vo is: " + this.masterVoClass.getName());
    	return this.masterVoClass;
    }
        
    //not supported yet
	protected Class[] getChildRowClass(){
//		Class[] childRowClass = new Class[5];
//		childRowClass[0] = com.erp.app.sourcing.so.web.SoDtlRow.class;
//		childRowClass[1] = com.erp.app.sourcing.so.web.SoScheduleRow.class;
//		childRowClass[2] = com.erp.app.sourcing.so.web.SoChargesRow.class;
//		childRowClass[3] = com.erp.common.web.ItemTaskRow.class;
//		childRowClass[4] = com.erp.common.web.GenericDocumentLinkRow.class;
//		return childRowClass;
		return null;
	}

    //not supported yet
    protected String[] getFolderChildIdxMapping(){
    	return null;
    }
      
    //not supported
    protected SimpleBasePk getPk(ActionForm formIn, HttpServletRequest request){
    	return null;
    }
    
    protected void setFormType(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors){
    	PopUpForm form = (PopUpForm) formIn;
		form.setFormType(ProjectConstants.FORM_TYPE_MAINT);
    }
    
    protected ActionForward handlePageEvent(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors) {

        return null;
    }
}
